<?php
namespace app\common\model\merchant;

use app\common\model\BaseModel;

/**
 * 商户模型
 * 管理商户注册、认证、API密钥等信息
 */
class MerchantModel extends BaseModel
{
    public static function tableName(): string { return 'gf_merchants'; }

    public static function tablePk(): ?string
    {
        return 'id';
    }

    /**
     * 获取商户的API密钥
     */
    public function getApiKeys()
    {
        return $this->hasMany(MerchantApiKeyModel::class, 'merchant_id', 'id');
    }

    /**
     * 获取商户的应用
     */
    public function getApps()
    {
        return $this->hasMany(\app\common\model\apps\AppsModel::class, 'merchant_id', 'id');
    }

    /**
     * 检查商户状态是否正常
     */
    public function isActive()
    {
        return $this->status === 'active' && $this->verified_at !== null;
    }
}